﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Jy123.Common;
using Jy123.Common.Config;
namespace Jy123.BLL.UI
{
    public class UserPage
    {
        /// <summary>
        /// 设置登录的Cookie
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="userName">用户姓名</param>
        /// <param name="Password">已Md5加密后的密码</param>
        /// <param name="userPortrait">用户的头像</param>
        /// <param name="isAlways">是否保持登录状态(下次同一计算机免登录)</param>
        static public void SetCookie(int userId, string userName, string Password, string userPortrait, bool isAlways)
        {
            HttpCookie SNSToKenCookie = new HttpCookie("SNSUserPassPort");

            string s = userId.ToString() + SecretConfig.UserSeparator.ToString() + Password + SecretConfig.UserSeparator.ToString() + Common.Public.GetClientIP();
            SNSToKenCookie["token"] = DES.Encrypt(s, SecretConfig.UserKey, SecretConfig.UserIV);
            SNSToKenCookie["headpic"] = userPortrait;
            SNSToKenCookie["username"] = Input.URLEncode(userName);
            SNSToKenCookie.Domain = UiConfig.CookieDomain;
            SNSToKenCookie.Secure = false;
            if (isAlways)
            {
                SNSToKenCookie.Expires = DateTime.Now.AddYears(1);
            }
            HttpContext.Current.Response.AppendCookie(SNSToKenCookie);
        }

    }
}
